<?php

use yii\helpers\Inflector;
use yii\helpers\StringHelper;

/* @var $this yii\web\View */
/* @var $generator yii\gii\generators\crud\Generator */

$urlParams = $generator->generateUrlParams();

echo "<?php\n";
?>

use yii\helpers\Html;
use \kartik\detail\DetailView;
/* @var $this yii\web\View */
/* @var $model <?= ltrim($generator->modelClass, '\\') ?> */

$this->title = $model-><?= $generator->getNameAttribute() ?>;
$this->params['breadcrumbs'][] = ['label' => <?= $generator->generateString(Inflector::pluralize(Inflector::camel2words(StringHelper::basename($generator->modelClass)))) ?>, 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="<?= Inflector::camel2id(StringHelper::basename($generator->modelClass)) ?>-view">

    <p>
        <?= "<?= " ?>Html::a(<?= $generator->generateString('Update') ?>, ['update', <?= $urlParams ?>], ['class' => 'btn btn-primary']) ?>
        <?= "<?= " ?>Html::a(<?= $generator->generateString('Delete') ?>, ['delete', <?= $urlParams ?>], [
            'class' => 'btn btn-danger',
            'data' => [
                'confirm' => <?= $generator->generateString('Are you sure you want to delete this item?') ?>,
                'method' => 'post',
            ],
        ]) ?>
    </p>

    <?= "<?= " ?>DetailView::widget([
        'model' => $model,
        'condensed'=>true,
        'mode'=>DetailView::MODE_VIEW,
        'hover'=>true,
        'attributes' => [
<?php
if (($tableSchema = $generator->getTableSchema()) === false) {
    foreach ($generator->getColumnNames() as $name) {
        echo "            '" . $name . "',\n";
    }
} else {
    // add columns 3 with each row in deatil view
    // edit by holy 2016-11-2;
    $_tableColsCount = count($generator->getTableSchema()->columns);
    $_columnTemplate = "                ['columns' => [\n{attribute}                  ],\n                ],// end columns\n";

    ////{format}
    $_attrTemplate = "                    [
                        'attribute'=>'{attributeName}',
                        'labelColOptions'=>['style'=>'width:14%'],
                        'valueColOptions'=>['style'=>'width:16%'],{format}
                    ],\n";
    // 取当前列;
    $_currentCol = 1;
    $_echoColumns = "";
    $_element = '';

    foreach ($generator->getTableSchema()->columns as $column) {

        $format = $generator->generateColumnFormat($column);
        $_format = '';
        if ($format !== 'text'){
            $_format = "\n".'                        \'format\' => \''. $format .'\',';
        }

        $_col = strtr($_attrTemplate, ['{attributeName}' => $column->name]);
        $_col = strtr($_col, ['{format}' => $_format]);

        // 取3的余数;如果为0 则包columns 属性;&& $_currentCol > 1
        if ($_currentCol % 3 == 0 ){
            $_element .= $_col;
            $_element = strtr($_columnTemplate, ['{attribute}' => $_element]);
            $_echoColumns .= $_element;
            $_element = '';

        }else{
            $_element .= $_col;
        }

        if  ($_currentCol == count($generator->getTableSchema()->columns) &&  $_element !== ''){
            $_element = strtr($_columnTemplate, ['{attribute}' => $_element]);
            $_echoColumns .= $_element;
        }
        $_currentCol ++;

    }
    echo $_echoColumns;
}
?>
        ],
    ]) ?>

</div>
